package com.explorati.interview.interview.chapterfour;

import java.math.BigDecimal;

public class BigDecimalTest {

	public static void main(String[] args) {
		System.out.println(0.05 + 0.01);
		System.out.println(1.0 - 0.42);
		System.out.println(4.015 * 100);
		System.out.println(123.3 / 100);
		/**
		 * 输出结果为： 0.060000000000000005 0.5800000000000001 4 01.49999999999994
		 * 1.2329999999999999
		 */
		System.out.println("=======================");

		BigDecimal v1 = new BigDecimal(Double.toString(0.05 + 0.01));
		System.out.println("v1 = " + v1.doubleValue());
		BigDecimal v2 = BigDecimal.valueOf(0.01);
		System.out.println("v2 = " + v2.doubleValue());
		BigDecimal v3 = v1.valueOf(0.01);
		System.out.println("v3 =  " + v3.doubleValue());

		System.out.println("=====================");
		System.out.println(add(0.01, 0.05));
	}

	public static double add(double v1, double v2) {
		BigDecimal b1 = new BigDecimal(Double.toString(v1));
		BigDecimal b2 = new BigDecimal(Double.toString(v2));
		return b1.add(b2).doubleValue();
		
	}
}
